package mysql

import (
	"gorm.io/gorm"
	"novel-sys/goods/goods"
)

type User struct {
	gorm.Model
	Mobile    string `gorm:"type:varchar(50)"`
	Password  string `gorm:"type:varchar(50)"`
	HeadImage string `gorm:"type:varchar(500)"`
	NickName  string `gorm:"type:varchar(50)"`
}

func (u *User) Register(db *gorm.DB, in *goods.LoginRegisterRequest) error {
	return db.Debug().Where("mobile=?", in.Mobile).FirstOrCreate(u).Error
}

func (u *User) UserByMobile(db *gorm.DB, mobile string) error {
	return db.Debug().Where("mobile=?", mobile).Find(u).Error
}

func (u *User) UpdatePassword(db *gorm.DB, mobile string) error {
	return db.Debug().Where("mobile=?", mobile).Updates(u).Error
}
